<?php
namespace App;

use System\Core\Controller;
use System\Core\Request;

class BaseController extends Controller {

    protected function result($code,$msg='',$merge=[],$data=[]){
        header('Content-Type:application/json;charset=utf-8');
        $arr = [
            'code' => $code,
            'msg'  => $msg,
            'data' => $data,
            'time' => time()
        ];
        if(!empty($merge)){
            $arr = array_merge($arr,$merge);
        }
        echo json_encode( $arr,true);
        exit;
    }

    protected function error($msg = '',$data = [],$merge=[],$code = 0){
        return $this->result($code,$msg,$merge,$data);
    }

    protected function success($msg = '',$data = [],$merge=[],$code = 1){
        return $this->result($code,$msg,$merge,$data);
    }
}